package com.cs.manaer.service;

import com.cs.manaer.common.utils.RedisSerializableUtils;
import com.cs.manaer.controller.req.MenuReqMsg;
import com.cs.manaer.controller.req.RoleReqMsg;
import com.cs.manaer.controller.res.ListCsmgMenuResMsg;
import com.cs.manaer.dao.CsmgMenuMapper;
import com.cs.manaer.po.CsmgMenu;
import com.lin.common.constant.CommonConstant;
import com.lin.common.error.CustomRuntimeException;
import com.lin.common.utils.BeanCopyUtils;
import com.lin.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CsmgMenuServiceImpl implements CsmgMenuService {
    @Autowired
    private CsmgMenuMapper csmgMenuMapper;

    @Override
    public ListCsmgMenuResMsg listmenu(Integer pageSize, Integer pageNo) {
        ListCsmgMenuResMsg cm = new ListCsmgMenuResMsg();
        cm.setRecords(csmgMenuMapper.listmenu(pageSize, pageNo));
        cm.setTotal(csmgMenuMapper.listmenucount());
        return cm;
    }

    @Override
    public Integer addmenu(MenuReqMsg reqMsg) throws CustomRuntimeException {
        CsmgMenu m = BeanCopyUtils.beanCopy(reqMsg, CsmgMenu.class);
        m.setMenuId(Long.parseLong(RedisSerializableUtils.generateForLong(CommonConstant.DEFAULT_LENGTH)));
        m.setCreateTime(DateUtils.fullDateFormat());
        m.setUpdateTime(DateUtils.fullDateFormat());

        return csmgMenuMapper.insertSelective(m);
    }

    @Override
    public Integer delmenu(Long id) {
        return csmgMenuMapper.deleteByPrimaryKey(id);
    }
}
